package com.haohan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haohan.dao.ServerInfoDao;
import com.haohan.domain.ServerInfo;
import com.haohan.service.ServerInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: jzhou
 * @date: 2024/12/20-14:31
 * @version: 1.0
 * @description: compass
 */
@Service
public class ServerInfoServiceImpl extends ServiceImpl<ServerInfoDao, ServerInfo> implements ServerInfoService {

    @Autowired
    private ServerInfoDao serverInfoDao;


    @Override
    public boolean saveBatch(List<ServerInfo> serverInfoList) {
        return serverInfoDao.saveBatch(serverInfoList) > 0;
    }

    @Override
    public IPage<ServerInfo> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        serverInfoDao.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<ServerInfo> getPage(int currentPage, int pageSize, ServerInfo serverInfo) {
        // 组织条件
        LambdaQueryWrapper<ServerInfo> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(serverInfo.getBmcUser()),ServerInfo::getBmcUser,serverInfo.getBmcUser());
        lqw.like(StringUtils.isNotEmpty(serverInfo.getUsername()),ServerInfo::getUsername,serverInfo.getUsername());
        lqw.eq(StringUtils.isNotEmpty(serverInfo.getRack()),ServerInfo::getRack,serverInfo.getRack());

        IPage page = new Page(currentPage,pageSize);
        serverInfoDao.selectPage(page,lqw);
        return page;
    }
}
